require("./assets/vendor/avalon/dist/avalon.mobile.shim.js");
require("./assets/vendor/mui/dist/css/mui.css");
// require('./assets/css/iconfont.css');
// require('./assets/css/style.css');
//项目入口
require("./assets/vendor/avalon/dist/mmRequest.js");
require("./assets/vendor/avalon/dist/mmState.js");
require("./assets/vendor/avalon/dist/mmAnimate.js");
require("./assets/vendor/mui/dist/js/mui.js");
// 定义一个顶层的vmodel，用来放置全局共享数据
var root = avalon.define({
    $id: "main",
    testpro: "testpro"
});

/**
 * 首页路由
 */
avalon.state("home", {
    url: "/home",

    views: {
        "": {
            //配置模块模板和控制器
            templateProvider: function () {
                return new Promise(function (rs) {
                    require.ensure([], function (tt) {
                        rs(require("text!./modules/home/home.html"))
                    })
                })
            },
            controllerProvider: function () {
                return new Promise(function (rs) {
                    require.ensure([], function () {
                        rs(require("./modules/home/home.js"))
                    })
                })
            }
        }
    }
});

avalon.state("project", {
    url: "/project",
    views: {
        "": {
            //配置模块模板和控制器
            templateProvider: function () {
                return new Promise(function (rs) {
                    require.ensure([], function (tt) {
                        rs(require("text!./modules/project/project.html"))
                    })
                })
            },
            controllerProvider: function () {
                return new Promise(function (rs) {
                    require.ensure([], function () {
                        rs(require("./modules/project/project.js"))
                    })
                })
            }
        }
    }
});

avalon.state("about", {
    url: "/about",
    views: {
        "": {
            //配置模块模板和控制器
            templateProvider: function () {
                return new Promise(function (rs) {
                    require.ensure([], function (tt) {
                        rs(require("text!./modules/about/about.html"))
                    })
                })
            },
            controllerProvider: function () {
                return new Promise(function (rs) {
                    require.ensure([], function () {
                        rs(require("./modules/about/about.js"))
                    })
                })
            }
        }
    }
});

/**
 * 路由全局配置
 */
avalon.state.config({
    // 全局的onBeforeUnload
    onBeforeUnload: function (from, to) {
        //                      if(confirmed) return
        //                      if(to && to.stateName.indexOf("contacts") == 0) {
        //                          confirmed = confirm("读取contacts需要授权，确认授权？")
        //                          return confirmed
        //                      }
    },

    onBegin: function (from, to) {
        var loading = avalon.vmodels.loading
        if (loading) loading.toggle = true
    },
    onLoad: function (from, to) {
        var loading = avalon.vmodels.loading
        if (loading) loading.toggle = false
    },
    onError: function (keyname, state) {
        console.log(arguments)
        // avalon.router.navigate("/", {replace: true})
    },
    onViewEnter: function (newNode, oldNode) {
        avalon(oldNode).animate({
            marginLeft: "-100%"
        }, 500, function () {
            oldNode.parentNode && oldNode.parentNode.removeChild(oldNode)
        })

    } // 不建议使用动画，因此实际使用的时候，最好去掉onViewEnter和ms-view元素上的oni-mmRouter-slide

});
avalon.history.start({
    basepath: "/",
    fireAnchor: false
});
//开始扫描编译
avalon.scan();
avalon.router.go("home");
